package org.bot.server.log.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.bot.server.log.entity.BotClientLog;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author 沧月
 * @create 0020 2023/10/20 10:38
 * @description <description class purpose>
 */
@Mapper
@Repository
public interface BotClientLogMapper extends BaseMapper<BotClientLog> {

    @Select("<script>select bot_flow.flow_name,bot_client_log.* from bot_client_log join bot_flow on bot_client_log.flow_id = bot_flow.id " +
            "<where><if test='flowId!=null'> flow_id = #{flowId} </if></where> order by creation_date desc limit #{page},#{size}</script>")
    List<Map<String, Object>> list(@Param("flowId") Integer flowId, @Param("page") int page, @Param("size") int size);

    @Select("<script>select count(1) as num from bot_client_log join bot_flow on bot_client_log.flow_id = bot_flow.id " +
            "<where><if test='flowId!=null'> flow_id = #{flowId} </if></where></script>")
    int count(@Param("flowId") Integer flowId);

    @Select("select id,flow_name from bot_flow where client_id = #{flowId}")
    List<Map<String, Object>> flowList(@Param("flowId") Integer flowId);
}
